<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>添加部门</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var parentId = new Ext.form.Hidden({
          name: 'parent_id',
          value:'<%=params[:parent_id]%>'
        });
        
        var name = new Ext.form.TextField({
          fieldLabel: '名称',
          allowBlank: false,
          blankText: "部门名称不能为空",
          name: 'name',
          anchor: '95%'
        });

        var number = new Ext.form.TextField({
          fieldLabel: '编号',
          allowBlank: false,
          blankText: "部门名称不能为空",
          name: 'number',
          anchor: '95%'
        });

        var departmentSubTypeStore = new Ext.data.ArrayStore({
          //fields: ['value', 'text'],
          fields: ['text'],
          data : departmentSubTypeArray
        });

        var departmentSubType = new Ext.form.ComboBox({
          fieldLabel: '部门类型',
          store: departmentSubTypeStore,
          valueField:'text',
          displayField:'text',
          typeAhead: true,
          mode: 'local',
          triggerAction: 'all',
          editable:false,
          selectOnFocus:true,
          name:'sub_type',
          emptyText:'请选择部门类型...',
          allowBlank: false,
          anchor: '95%'
        });

        var desc = new Ext.form.TextArea({
          fieldLabel: '描述',
          name: 'description',
          height:80,
          anchor: '95%'
        });
        
        var newDepartmentForm = new Ext.FormPanel({
          labelWidth: 55, // label settings here cascade unless overridden
          url:'/department/create',
          frame:true,
          //title: '添加部门',
          bodyStyle:'padding:5px 5px 0',
          width: 310,
          //height:300,
          items: [parentId,name,number,departmentSubType,desc],
          buttons: [{
              text: '提交',
              handler: function(){
                // check form value
                if (newDepartmentForm.form.isValid()) {
                  newDepartmentForm.form.submit({
                    method: 'GET',
                    success: function(result, response){
                      if (response.result.info == "成功") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        newDepartmentWin.destroy();
                        departmentTree.root.reload();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text: '取消',
              handler: function(){
                newDepartmentWin.destroy();
              }
            }]
        });
        newDepartmentForm.render('new_department_form');
      })
    </script>
  </head>
  <body>
    <div id="new_department_form"></div>
  </body>
</html>
